import { createRouter, createWebHistory } from 'vue-router'
import MainView from '../views/MainView.vue'
import CatalogDetailView from '../views/CatalogDetailView.vue'
import ProductDetailView from '../views/ProductDetailView.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: MainView
  },
  {
    path: '/catalog/:id',
    name: 'CatalogDetail',
    component: CatalogDetailView,
    props: true
  },
  {
    path: '/catalog/:categoryId/:productId',
    name: 'ProductDetail',
    component: ProductDetailView,
    props: true
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(_to, _from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router